package com.jy.servlet;

import java.io.IOException;
import java.lang.reflect.Method;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class BaseServlet
 */
public class BaseServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String url=request.getRequestURI();//获取正在访问的路径
		int g=url.lastIndexOf("/");
		String method=url.substring(g+1);
		System.out.println("你正在访问="+method);
		try {
			Method m=this.getClass().getDeclaredMethod(method, HttpServletRequest.class,HttpServletResponse.class);
			m.setAccessible(true);
			m.invoke(this, request,response);
		} catch (Exception e) {
			e.printStackTrace();
		}
		/*	String m=request.getParameter("m");
		if("add".equals(m)){
			add(request, response);
		}else if("del".equals(m)){
			del(request, response);
		}
	*/
	
	}
}
